<?php include_once ("../controller/asset_list.php");?>
<?php include_once ("module/head.php");?>
<body>
<?php include_once ("module/header.php");?>

<?php //include_once ("module/lightbox.php");?>

<header class="base" style="margin-top: 110px">
    <div class="tool-bar clearfix" style="display: block">
        <div class="filters-holder cropped" style="width: 1149.42px;">
            <ul class="filters clearfix" style="margin-left: 0px;">
                <?php include_once ("module/mod-select-brand.php");?>
                <?php include_once ("module/mod-select-product.php");?>
                <?php include_once ("module/mod-select-assettype.php");?>
                <?php include_once ("module/mod-select-filetype.php");?>
                <?php include_once ("module/mod-select-advance.php");?>
                <?php include_once ("module/mod-select-tag.php");?>
            </ul>
        </div>
    </div>
</header>







    <?php include_once ("module/toolbar.php");?>








<!--产品缩略图列表-->
            <div id="results-thumbs" class="StyledContainer-sc-1i0dzpl-0 fXGiFm"
                <? if($_REQUEST['sort'] == 'list'){ echo 'style=" padding-left:20px;padding-right:20px;"';}?> >

                <?
                if($_REQUEST['sort'] == 'list'){?>
                <div class="StyledRow-sc-xqkn0o-0 fSGkgo row listviewrow clearfix">
                    <?
                }
                ?>
            <? foreach ($_asset_list as $key=>$asset){

                    if($_REQUEST['sort'] == 'grid'){


                ?>

                <div class="media-holder transition" width="224" onclick="open_box(<?echo $asset['nid']?>)">
                    <a class="thumbnail" >
                        <div class="ImageContainer-sc-19bttq8-2 gNEuKI image-holder iskip pptx"
                             height="140">
                            <?if($asset['icon']){?>
                                <img src="/uploadfiles/<?echo $asset['icon']?>">
                            <?;}else{?>
                                <img src="/uploadfiles/<?echo $asset['asset_id']?>.jpg">
                            <?;}?>
                            <span class="IconExtension-sc-13p706v-0 loKyBz extension pptx">
                                <?echo $asset['file_type']?>
                            </span>
                        </div>
                        <div class="select">
                        </div>
                        <p>
                            <?echo $asset['title']?>
                        </p>
                        <dl >
                            <dt data-name="Brand" class="StyledDt-sc-1ijb1g4-0 bguRNK">
                                Brand
                            </dt>
                            <dd class="StyledDd-sc-1ijb1g4-1 gtsNXy">
                                <?echo $asset['brand']?>
                            </dd>
                            <br>
                            <dt  class="StyledDt-sc-1ijb1g4-0 bguRNK">
                                Product Range
                            </dt>
                            <dd
                                class="StyledDd-sc-1ijb1g4-1 gtsNXy">
                                <?
                                $_category=explode(",", $asset['product_category']);
                                foreach ( $_category as $v)
                                {echo  $category_name_list[$v];}
                                ?>
                            </dd>
                            <br>
                        </dl>
                    </a>
                </div>
            <?;}
                else{
                    ?>

                        <div class="media-holder listview list-media-view ui-selectee landscape" onclick="open_box(<?echo $asset['nid']?>)">
                            <a class="ThumbnailContainer-sc-9k3xa3-0 dNIYfd thumbnail" >
                                <div class="image-holder pdf">
                                    <img src="/uploadfiles/<?echo $asset['asset_id']?>.jpg">
                                </div>
                                <div class="select"></div>
                                <p> <?echo $asset['title']?></p>
                                <span class="IconExtension-sc-13p706v-0 loKyBz extension pdf" >  <?echo $asset['file_type']?></span>
                            </a>
                            <ul class="listview-info">
                                <li>
                                    <strong class="StyledAssetName-sc-v0jk6q-0 eRhYJL">700 Series From Studio to Home - Toolkit</strong>
                                </li>
                                <dl></dl>
                            </ul>
                        </div>


                <?
                }
            }
                    ?>
                <?
                if($_REQUEST['sort'] == 'list'){?>
            </div>>
                    <?
                    }
                    ?>

                <div id="page" date-attr='1' style="display: none"></div>

            </div>


<div style="margin-bottom: 250px"></div>






 <script>
    $(document).ready(function(){
        $('.filter').click(function(e){
            if ($(this).hasClass('active')) {
                $(this).removeClass('active');
            } else {
                $(this).addClass('active').siblings('.filter').removeClass('active');
            }

            //如果当前点击的元素，不带有data-attr= advanced 的，都执行
            if ($(this).attr('data-attr') != 'advanced')
            {
                $('.advance:visible').hide();
            }
        })
    })





    // 定义一个变量来跟踪是否正在加载内容，防止重复加载
    let isLoading = false;

    // 监听窗口的滚动事件
    window.addEventListener('scroll', () => {
        // 获取窗口的高度
        const windowHeight = window.innerHeight;
        // 获取文档的总高度
        const documentHeight = document.documentElement.scrollHeight;
        // 获取窗口的滚动位置
        const scrollPosition = window.pageYOffset || document.documentElement.scrollTop;

        // 判断是否滚动到底部
        if (windowHeight + scrollPosition >= documentHeight && !isLoading) {
            // 设置正在加载标志
            isLoading = true;

            // 执行 AJAX 请求加载更多内容
            loadMoreContent();
        }
    });

    // 定义加载更多内容的函数
    function loadMoreContent() {

        console.log("loadMoreContent");

        domain = "<?php echo $domain ?>";
        page_number=$('#page').attr('date-attr');

        api = "module/mod_asset_list.php?<?php echo $url_parameter; ?>&now_page="+page_number+"&sort=<?php echo $_REQUEST['sort']?>";
        console.log(api);

        //把url的页面内容加入到页面中 id="page" 的元素前
        $.ajax({
            url: api,
            type: "GET",
            data: {
                now_page: $('#page').attr('date-attr')
                 },
            success: function(data) {
                $('#page').attr('date-attr',parseInt($('#page').attr('date-attr'))+1);
                $('#results-thumbs').append(data);
                isLoading = false;
                if(data==""){
                    $('.filter-navigation').css('display','none');
                }
            }
            })
        }

</script>


<script>

    layui.laydate.render({
        elem: '#date_start'
        ,format: 'yyyy-MM-dd' //可任意组合
    });
    layui.laydate.render({
        elem: '#date_end'
        ,format: 'yyyy-MM-dd' //可任意组合
    });


    function close_box(){
        layui.use('layer', function(){ //独立版的layer无需执行这一句
            var layer = layui.layer; //独立版的layer无需执行这一句
            layer.closeAll();
        });
    }
    function open_box(goods_id){
        layui.use('layer', function(){ //独立版的layer无需执行这一句
            var layer = layui.layer; //独立版的layer无需执行这一句

            domain = "<?php echo $domain ?>";

            api = "module/lightbox.php?nid="+goods_id;

            //把url的页面内容加入到页面中 id="page" 的元素前
            $.ajax({
                url: api,
                type: "GET",
                data: {

                },
                success: function(data) {
                    layer.open({
                        type: 1
                        ,offset:  'auto'//具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemo'//防止重复弹出
                        ,content: '<div style="padding: 20px 100px;">'+data+'</div>'

                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,area: ['100%', '100%']
                        ,yes: function(){
                            layer.closeAll();
                        }
                    });
                }
            })

        });
    }

    function add_collection(goods_id){

            domain = "<?php echo $domain ?>";

            api = "../controller/collection.php?act=ajax&nid="+goods_id;

            //把url的页面内容加入到页面中 id="page" 的元素前
            $.ajax({
                url: api,
                type: "GET",
                data: {

                },
                success: function(res) {
                    if(res == 1){
                        layer.msg('收藏成功', {icon: 1});
                    }
                    else if(res == 0){
                        layer.msg('已收藏', {icon: 1});
                    }
                    else{
                        layer.msg('收藏失败', {icon: 2});
                    }
                }
            })

    }

</script>
</body>
</html>

